//
//  GJFMineHeaderView.m
//  Wedding
//
//  Created by 郭静芬 on 2017/1/10.
//  Copyright © 2017年 郭静芬. All rights reserved.
//

#import "GJFMineHeaderView.h"


@interface GJFMineHeaderView ()
@property (nonatomic, strong) UIImageView *backView;
@property (nonatomic, strong) UIImageView *avatar;
@property (nonatomic, strong) UILabel *nickName;
@property (nonatomic, strong) UIVisualEffectView *bV;
@property (nonatomic, strong) UILabel *userSign;
@end

@implementation GJFMineHeaderView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(0);
        }];
        [self.bV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(0);
        }];
        [self.avatar mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self).mas_offset(50 * YY);
            make.size.mas_equalTo(CGSizeMake(100 * YY, 100 * YY));
            make.centerX.mas_equalTo(self);
        }];
        [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.avatar.mas_bottom).mas_offset(10 * YY);
            make.left.right.mas_equalTo(self).mas_offset(0);
            make.height.mas_equalTo(30 * YY);
        }];
        [self.userSign mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.nickName.mas_bottom).mas_offset(10 * YY);
            make.left.right.mas_equalTo(self).mas_offset(0);
            make.height.mas_equalTo(20 * YY);
        }];
    }
    return self;
}

- (void)reloadData {
    GJFUserInfo *user = [[GJFSingleTool shareInstance] userInfo];
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:user.avatar] placeholderImage:[UIImage imageNamed:@"icon-头像账户编辑"]];
    if ([GJFSingleTool is_login]) {
        self.nickName.text = user.nickname?:@"昵称";
        self.userSign.text = user.signature?:@"个性签名";
    }
    else {
        self.nickName.text = @"幻紫琉晶";
        self.userSign.text = @"点击头像进行注册";
    }
}

- (void)clickAvatar {
    if (_delegate && [_delegate respondsToSelector:@selector(skipEditPerson)]) {
        [_delegate skipEditPerson];
    }
}

- (UIImageView *)backView {
    if (!_backView) {
        _backView = [[UIImageView alloc] init];
        _backView.image = [UIImage imageNamed:@"mineheaderImg"];
        _backView.contentMode = UIViewContentModeScaleAspectFill;
        _backView.clipsToBounds = YES;
        [self addSubview:_backView];
    }
    return _backView;
}
- (UIVisualEffectView *)bV {
    if (!_bV) {
        UIBlurEffect *b = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        _bV = [[UIVisualEffectView alloc] initWithEffect:b];
        _bV.alpha = 0.5;
        [self.backView addSubview:_bV];
    }
    return _bV;
}
- (UIImageView *)avatar {
    if (!_avatar) {
        _avatar = [[UIImageView alloc] init];
        _avatar.layer.borderColor = HOMECOLOR.CGColor;
        _avatar.layer.borderWidth = 0.5;
        _avatar.layer.cornerRadius = 50 * YY;
        _avatar.clipsToBounds = YES;
        _avatar.contentMode = UIViewContentModeScaleAspectFill;
        _avatar.userInteractionEnabled = YES;
        [self addSubview:_avatar];
        UITapGestureRecognizer *tapAvatar = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAvatar)];
        [_avatar addGestureRecognizer:tapAvatar];
    }
    return _avatar;
}

- (UILabel *)nickName {
    if (!_nickName) {
        _nickName = [[UILabel alloc] init];
        _nickName.textAlignment = NSTextAlignmentCenter;
        _nickName.textColor = [UIColor whiteColor];
        _nickName.font = [UIFont boldSystemFontOfSize:22 * XX];
        [self addSubview:_nickName];
    }
    return _nickName;
}
- (UILabel *)userSign {
    if (!_userSign) {
        _userSign = [[UILabel alloc] init];
        _userSign.textAlignment = NSTextAlignmentCenter;
        _userSign.textColor = [UIColor whiteColor];
        _userSign.font = [UIFont systemFontOfSize:15 * XX];
        [self addSubview:_userSign];
    }
    return _userSign;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
